home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DrawLine.c
-
- Contains: This application shows how to use the QuickDraw
- pattern mode 'srcCopy' to invert the intersection
- of the two green lines.
-
- Written by: GH
-
- Copyright: Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 08/2000 JM Carbonized, non-Carbon code is commented out
- for demonstration purposes.
- 7/9/1999 KG Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
- #include "CarbonPrefix.h"
- #include <Controls.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Sound.h>
-
- #define KBaseResID 128
- #define kMoveToFront (WindowPtr)-1L
-
-
- /*********************/
- /* Functions */
- /*********************/
-
- void ToolBoxInit( void );
- void WindowInit( void );
- void DrawLine( void );
- void doEventLoop( void );
-
-
- /*************** main ***************/
-
- void main( void )
-
- {
- ToolBoxInit();
- WindowInit();
- //DrawLine();
-
- //while ( !Button() );
- doEventLoop();
-
- }
-
- /*************** ToolBoxInit ***************/
-
- void ToolBoxInit( void )
-
- {
- // Toolbox initialization taken care of in carbon, the exception
- // being the InitCursor call
-
- //InitGraf(&qd.thePort); /* init Quickdraw and global variables */
- //InitFonts();
- //InitWindows();
- //InitMenus();
- //TEInit();
- //InitDialogs( nil );
- InitCursor();
-
- }
-
- /*************** WindowInit ***************/
-
- void WindowInit( void )
-
- {
- WindowPtr window;
-
- window = GetNewCWindow( KBaseResID, nil, kMoveToFront );
-
- if ( window == nil )
- {
- SysBeep ( 10 ); /* Couldn't load the WIND resource! */
- ExitToShell();
- }
-
- ShowWindow( window );
- SetPortWindowPort( window );
- }
-
- /*************** Draw two Lines ***************/
-
- void DrawLine( )
- {
- Rect pictureRect;
- WindowPtr window;
- GrafPtr oldPort;
-
- GetPort(&oldPort);
-
- window = FrontWindow();
- SetPortWindowPort(window);
- // Can't directly access in carbon
- //pictureRect = window->portRect;
- GetPortBounds(GetWindowPort(window), &pictureRect);
-
- PenNormal() ;
- PenSize(5,5);
-
- ForeColor( blackColor );
- PenMode(srcCopy);
- MoveTo( 50, 47 );
- LineTo( 300,231 );
-
- PenMode(srcXor);
- MoveTo( 400, 47 );
- LineTo( 200,231 );
-
-
- ForeColor( greenColor );
- PenMode(addMax);
- MoveTo( 50, 47 );
- LineTo(300,231);
-
- PenMode(addMax);
- MoveTo( 400, 47 );
- LineTo( 200,231 );
-
- SetPort(oldPort);
-
- }
-
- /*************** The Event Loop ***************/
- void doEventLoop()
- {
- EventRecord anEvent;
- WindowPtr evtWind;
- short clickArea;
- Rect screenRect;
- Point thePoint;
-
- for (;;)
- {
- if (WaitNextEvent( everyEvent, &anEvent, 0, nil ))
- {
- if (anEvent.what == mouseDown)
- {
- clickArea = FindWindow( anEvent.where, &evtWind );
-
- if (clickArea == inDrag)
- {
- GetRegionBounds( GetGrayRgn(), &screenRect );
- DragWindow( evtWind, anEvent.where, &screenRect );
- }
- else if (clickArea == inContent)
- {
- if (evtWind != FrontWindow())
- SelectWindow( evtWind );
- else
- {
- thePoint = anEvent.where;
- GlobalToLocal( &thePoint );
- //Handle click in window content here
- }
- }
- else if (clickArea == inGoAway)
- if (TrackGoAway( evtWind, anEvent.where ))
- return;
- }
- else if (anEvent.what == updateEvt)
- {
- evtWind = (WindowPtr)anEvent.message;
- SetPortWindowPort( evtWind );
-
- BeginUpdate( evtWind );
- //Call Draw Function here....
- DrawLine();
- EndUpdate (evtWind);
- }
- }
- }
- }